package com.count.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.count.core.G;
import com.count.core.PlayerCount;
import com.count.core.PlayerInfo;
import com.count.core.TotalCount;

public class FileUtil {
	public static void readDirectory(String directoryPath, String nameFilter, List<G> gList) {
		File historyDirectory = new File(directoryPath);
		for (String file : historyDirectory.list()) {
			if (file.indexOf(nameFilter) > -1) {
				readFile(directoryPath + file, gList);
			}
		}
	}

	private static final String GAME_BEGIN_FLAG = "Hand #";
	private static final String MY_ID = "grinder_2015";
	

	public static void readFile(String path, List<G> gList) {
		File file = new File(path);
		BufferedReader reader = null;

		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			String oneGame = "";
			G g = null;
			while ((tempString = reader.readLine()) != null) {
				if (tempString.indexOf(GAME_BEGIN_FLAG) > -1) {
					if (g != null) {
						g.getGinfo().setGameStr(oneGame);
						g.process();
						gList.add(g);
					}
					g = new G(MY_ID);
					g.getGinfo().setTitle(tempString);
					gList.add(g);
					oneGame = "";
				} else {
					oneGame = oneGame + tempString + "\r\n";
				}
			}
			g.getGinfo().setGameStr(oneGame);
			g.process();
			gList.add(g);
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		List<G> glist = new ArrayList<G>();
		readDirectory("E:/hi/grinder_2015/", "Halley", glist);
		
		TotalCount.count(glist);

		

		System.out.println(TotalCount.getPlayerCount("grinder_2015").getPreflopOpenRaise());
		System.out.println(TotalCount.getPlayerCount("grinder_2015").getPreflopThreebet());
		System.out.println(TotalCount.getPlayerCount("grinder_2015").getPreflopFourbet());
		System.out.println(TotalCount.getPlayerCount("grinder_2015").getPreflopFivebet());
		System.out.println(TotalCount.getPlayerCount("grinder_2015").getPreflopSixbet());

		System.out.println(TotalCount.getPlayerCount("grinder_2015").getPreflopOpenRaiseFold());
		System.out.println(TotalCount.getPlayerCount("grinder_2015").getPreflopThreebetFold());
		System.out.println(TotalCount.getPlayerCount("grinder_2015").getPreflopFourbetFold());
		System.out.println(TotalCount.getPlayerCount("grinder_2015").getPreflopFivebetFold());
		System.out.println(TotalCount.getPlayerCount("grinder_2015").getPreflopSixbetFold());
		
		System.out.println(glist.size());
		System.out.println(TotalCount.preflopThreeBet);
	}
}
